﻿// BizElements generated entity and metadata classes for VAdmTeamMembership.
using System;
using System.Data;
using System.Configuration;
using BizElements.Core;

namespace BizElements.BusinessLayer
{
	/// <summary>
	/// Entity model class for the table/view 'VAdmTeamMembership'.
	/// </summary>
	[Serializable]
	internal class VAdmTeamMembershipEntity : EntityModelBase
	{
		#region Private members.

		// Members mapped to database columns.
		private int? organizationId;
		private int? userId;
		private int? teamId;
		private bool? isTeamAdministrator;
		private bool? canWrite;
		private bool? canDelete;
		
		
		#endregion

		#region Protected properties.
    
		// Properties mapped to database columns.    
		/// <summary>
		/// Gets or sets the value which is mapped to the field 'OrganizationId'.
		/// </summary>
		protected int? _OrganizationId
		{
			get
			{
				return this.organizationId;
			}
			set
			{
				if (this.EntityState == EntityState.Synchronized)
				{
					if ((!value.HasValue != !this.organizationId.HasValue) || (value.HasValue && (value.Value != this.organizationId.Value)))
						this.EntityState = EntityState.OutOfSync;
				}
				this.organizationId = value;
			}
		}

		/// <summary>
		/// Gets or sets the value which is mapped to the field 'UserId'.
		/// </summary>
		protected int? _UserId
		{
			get
			{
				return this.userId;
			}
			set
			{
				if (this.EntityState == EntityState.Synchronized)
				{
					if ((!value.HasValue != !this.userId.HasValue) || (value.HasValue && (value.Value != this.userId.Value)))
						this.EntityState = EntityState.OutOfSync;
				}
				this.userId = value;
			}
		}

		/// <summary>
		/// Gets or sets the value which is mapped to the field 'TeamId'.
		/// </summary>
		protected int? _TeamId
		{
			get
			{
				return this.teamId;
			}
			set
			{
				if (this.EntityState == EntityState.Synchronized)
				{
					if ((!value.HasValue != !this.teamId.HasValue) || (value.HasValue && (value.Value != this.teamId.Value)))
						this.EntityState = EntityState.OutOfSync;
				}
				this.teamId = value;
			}
		}

		/// <summary>
		/// Gets or sets the value which is mapped to the field 'IsTeamAdministrator'.
		/// </summary>
		protected bool? _IsTeamAdministrator
		{
			get
			{
				return this.isTeamAdministrator;
			}
			set
			{
				if (this.EntityState == EntityState.Synchronized)
				{
					if ((!value.HasValue != !this.isTeamAdministrator.HasValue) || (value.HasValue && (value.Value != this.isTeamAdministrator.Value)))
						this.EntityState = EntityState.OutOfSync;
				}
				this.isTeamAdministrator = value;
			}
		}

		/// <summary>
		/// Gets or sets the value which is mapped to the field 'CanWrite'.
		/// </summary>
		protected bool? _CanWrite
		{
			get
			{
				return this.canWrite;
			}
			set
			{
				if (this.EntityState == EntityState.Synchronized)
				{
					if ((!value.HasValue != !this.canWrite.HasValue) || (value.HasValue && (value.Value != this.canWrite.Value)))
						this.EntityState = EntityState.OutOfSync;
				}
				this.canWrite = value;
			}
		}

		/// <summary>
		/// Gets or sets the value which is mapped to the field 'CanDelete'.
		/// </summary>
		protected bool? _CanDelete
		{
			get
			{
				return this.canDelete;
			}
			set
			{
				if (this.EntityState == EntityState.Synchronized)
				{
					if ((!value.HasValue != !this.canDelete.HasValue) || (value.HasValue && (value.Value != this.canDelete.Value)))
						this.EntityState = EntityState.OutOfSync;
				}
				this.canDelete = value;
			}
		}

		
		#endregion

		#region Constructors.

		/// <summary>
		/// Default constructor.
		/// </summary>
		public VAdmTeamMembershipEntity() 
			 : base(new VAdmTeamMembershipMeta())
		{
		}

		/// <summary>
		/// Constructor. Initalizes Table property with the specified (shared) instance.
		/// </summary>
		/// <param name="dbTable">Metadata for table/view to which the entity belongs to.</param>
		public VAdmTeamMembershipEntity(VAdmTeamMembershipMeta dbTable)
			: base(dbTable)
		{
		}
		
		/// <summary>
		/// Constructor. Initializes members with the values in the given DataRow.
		/// </summary>
		/// <param name="row">DataRow with required columns.</param>
		/// <remarks>If row's state is <see cref="DataRowState.Unchanged"/> the entity's state will be set to <see cref="EntityState.Synchronized"/>. Other states are ignored.</remarks>
		public VAdmTeamMembershipEntity(DataRow row) 
			 : base(new VAdmTeamMembershipMeta())
		{
			FromDataRow(row);
		}

		/// <summary>
		/// Constructor. Initializes members with the values in the given DataRow.
		/// </summary>
		/// <param name="dbTable">Metadata for table/view to which the entity belongs to.</param>
		/// <param name="row">DataRow with required columns.</param>
		/// <remarks>If row's state is <see cref="DataRowState.Unchanged"/> the entity's state will be set to <see cref="EntityState.Synchronized"/>. Other states are ignored.</remarks>
		public VAdmTeamMembershipEntity(VAdmTeamMembershipMeta dbTable, DataRow row) 
			 : base(dbTable)
		{
			FromDataRow(row);
		}

		/// <summary>
		/// Copy constructor.
		/// </summary>
		/// <param name="existing">Instance of VAdmTeamMembershipEntity.</param>
		public VAdmTeamMembershipEntity(VAdmTeamMembershipEntity existing) 
			 : base(existing.Table)
		{
			 FromExistingEntity(existing);
		}
    
		static readonly Type DbTableClass = typeof(VAdmTeamMembershipMeta);

		/// <summary>
		/// Initializes all members of VAdmTeamMembershipEntity and base EntityModelBase class. This is the fastest way to initialize entity with data from database.
		/// </summary>
		private VAdmTeamMembershipEntity(IDbTable table, EntityState entityState, int? organizationId, int? userId, int? teamId, bool? isTeamAdministrator, bool? canWrite, bool? canDelete) 
			 : base(table, DbTableClass, entityState)
		{
			this.organizationId = organizationId;
			this.userId = userId;
			this.teamId = teamId;
			this.isTeamAdministrator = isTeamAdministrator;
			this.canWrite = canWrite;
			this.canDelete = canDelete;
		}

		/// <summary>
		/// Initializes all members mapped to fields.
		/// </summary>
		protected void Init(int? organizationId, int? userId, int? teamId, bool? isTeamAdministrator, bool? canWrite, bool? canDelete)
		{
			_OrganizationId = organizationId;
			_UserId = userId;
			_TeamId = teamId;
			_IsTeamAdministrator = isTeamAdministrator;
			_CanWrite = canWrite;
			_CanDelete = canDelete;
		}

		#endregion

		#region Methods.

		/// <summary>
		/// Gets the value(s) that uniquely identifiy an entity.
		/// In the order as specified in accompanying IDbTable metadata class.
		/// NULL if the parent table/view doesn't have a primary key constraint or the required fields are not set.
		/// </summary>
		public override object[] GetPrimaryKeyValue()
		{
			return null;
		}

		/// <summary>
		/// Initializes entity members with data stored in the given DataRow.
		/// </summary>
		/// <param name="row">DataRow with the required columns.</param>
		/// <remarks>If row's state is <see cref="DataRowState.Unchanged"/> the entity's state will be set to <see cref="EntityState.Synchronized"/>. Other states are ignored.</remarks>
		public override void FromDataRow(DataRow row)
		{
			object currentColumnValue;
      
			currentColumnValue = TryGetColumnValue(row, "OrganizationId");
			_OrganizationId = (currentColumnValue != DBNull.Value) ? (int?) Convert.ToInt32(currentColumnValue) : null;
      
			currentColumnValue = TryGetColumnValue(row, "UserId");
			_UserId = (currentColumnValue != DBNull.Value) ? (int?) Convert.ToInt32(currentColumnValue) : null;
      
			currentColumnValue = TryGetColumnValue(row, "TeamId");
			_TeamId = (currentColumnValue != DBNull.Value) ? (int?) Convert.ToInt32(currentColumnValue) : null;
      
			currentColumnValue = TryGetColumnValue(row, "IsTeamAdministrator");
			_IsTeamAdministrator = (currentColumnValue != DBNull.Value) ? (bool?) Convert.ToBoolean(currentColumnValue) : null;
      
			currentColumnValue = TryGetColumnValue(row, "CanWrite");
			_CanWrite = (currentColumnValue != DBNull.Value) ? (bool?) Convert.ToBoolean(currentColumnValue) : null;
      
			currentColumnValue = TryGetColumnValue(row, "CanDelete");
			_CanDelete = (currentColumnValue != DBNull.Value) ? (bool?) Convert.ToBoolean(currentColumnValue) : null;
      
			bool setEntityStateToSynchronized = (row.RowState == DataRowState.Unchanged);
			if (setEntityStateToSynchronized)
				this.EntityState = EntityState.Synchronized;
		}

		private static object TryGetColumnValue(DataRow row, string columnName)
		{
			int colIdx = row.Table.Columns.IndexOf(columnName);
			return (colIdx >= 0) ? row[colIdx] : null;
		}

		private static object GetColumnValue(DataRow row, IDbColumn column)
		{
			int colIdx = row.Table.Columns.IndexOf(column.Alias);
			if (colIdx < 0)
				colIdx = row.Table.Columns.IndexOf(column.ColumnName);
			if (colIdx < 0)
				throw new ArgumentException("DataTable doesn't contain the specified column (" + column.ColumnName + ").");

			return row[colIdx];
		}

		/// <summary>
		/// Initializes entity members with data stored in the given DataRow.
		/// </summary>
		/// <param name="row">DataRow with all or some of the columns defined in meta data.</param>
		/// <param name="fieldMetaData"><see cref="IDbTable"/> meta data object which links ADO.NET row columns to entity properties.</param>
		/// <remarks>If row's state is <see cref="DataRowState.Unchanged"/> the entity's state will be set to <see cref="EntityState.Synchronized"/>. Other states are ignored.</remarks>
		public override void FromDataRow(DataRow row, IDbTable fieldMetaData)
		{
			IDbColumn currentColumn;
			object currentColumnValue;
      
			currentColumn = fieldMetaData.Columns.GetByPropertyName(this.Table.OrganizationId.PropertyName);
			currentColumnValue = (currentColumn != null) ? GetColumnValue(row, currentColumn) : DBNull.Value;
			_OrganizationId = (currentColumnValue != DBNull.Value) ? (int?) Convert.ToInt32(currentColumnValue) : null;
      
			currentColumn = fieldMetaData.Columns.GetByPropertyName(this.Table.UserId.PropertyName);
			currentColumnValue = (currentColumn != null) ? GetColumnValue(row, currentColumn) : DBNull.Value;
			_UserId = (currentColumnValue != DBNull.Value) ? (int?) Convert.ToInt32(currentColumnValue) : null;
      
			currentColumn = fieldMetaData.Columns.GetByPropertyName(this.Table.TeamId.PropertyName);
			currentColumnValue = (currentColumn != null) ? GetColumnValue(row, currentColumn) : DBNull.Value;
			_TeamId = (currentColumnValue != DBNull.Value) ? (int?) Convert.ToInt32(currentColumnValue) : null;
      
			currentColumn = fieldMetaData.Columns.GetByPropertyName(this.Table.IsTeamAdministrator.PropertyName);
			currentColumnValue = (currentColumn != null) ? GetColumnValue(row, currentColumn) : DBNull.Value;
			_IsTeamAdministrator = (currentColumnValue != DBNull.Value) ? (bool?) Convert.ToBoolean(currentColumnValue) : null;
      
			currentColumn = fieldMetaData.Columns.GetByPropertyName(this.Table.CanWrite.PropertyName);
			currentColumnValue = (currentColumn != null) ? GetColumnValue(row, currentColumn) : DBNull.Value;
			_CanWrite = (currentColumnValue != DBNull.Value) ? (bool?) Convert.ToBoolean(currentColumnValue) : null;
      
			currentColumn = fieldMetaData.Columns.GetByPropertyName(this.Table.CanDelete.PropertyName);
			currentColumnValue = (currentColumn != null) ? GetColumnValue(row, currentColumn) : DBNull.Value;
			_CanDelete = (currentColumnValue != DBNull.Value) ? (bool?) Convert.ToBoolean(currentColumnValue) : null;
      
			bool setEntityStateToSynchronized = (row.RowState == DataRowState.Unchanged);
			if (setEntityStateToSynchronized)
				this.EntityState = EntityState.Synchronized;
		}

		/// <summary>
		/// Converts the given DataRow to VAdmTeamMembershipEntity.
		/// </summary>
		/// <param name="row">DataRow with required columns.</param>
		/// <remarks>If row's state is <see cref="DataRowState.Unchanged"/> the entity's state will be set to <see cref="EntityState.Synchronized"/>. Other states are ignored.</remarks>
		public static explicit operator VAdmTeamMembershipEntity(DataRow row)
		{
			return new VAdmTeamMembershipEntity(row);
		}

		/// <summary>
		/// Creates an array of objects containing entity data.
		/// </summary>
		/// <returns>Entity values.</returns>
		public override object[] ToObjectArray()
		{
			object[] values = new object[6];
      
			values[0] = (_OrganizationId != null) ? (object) _OrganizationId.Value : null;
			values[1] = (_UserId != null) ? (object) _UserId.Value : null;
			values[2] = (_TeamId != null) ? (object) _TeamId.Value : null;
			values[3] = (_IsTeamAdministrator != null) ? (object) _IsTeamAdministrator.Value : null;
			values[4] = (_CanWrite != null) ? (object) _CanWrite.Value : null;
			values[5] = (_CanDelete != null) ? (object) _CanDelete.Value : null;
			
			return values;
		}

		/// <summary>
		/// Initializes entity members with the given values.
		/// </summary>
		/// <param name="entityValues">Array with the required values.</param>
		public override void FromObjectArray(object[] entityValues)
		{
			_OrganizationId = (entityValues[0] != null) ? (int?) Convert.ToInt32(entityValues[0]) : null;
			_UserId = (entityValues[1] != null) ? (int?) Convert.ToInt32(entityValues[1]) : null;
			_TeamId = (entityValues[2] != null) ? (int?) Convert.ToInt32(entityValues[2]) : null;
			_IsTeamAdministrator = (entityValues[3] != null) ? (bool?) Convert.ToBoolean(entityValues[3]) : null;
			_CanWrite = (entityValues[4] != null) ? (bool?) Convert.ToBoolean(entityValues[4]) : null;
			_CanDelete = (entityValues[5] != null) ? (bool?) Convert.ToBoolean(entityValues[5]) : null;
		}

		/// <summary>
		/// Gets the parent entity defined by the given foreign key.
		/// </summary>
		/// <param name="foreignKey">FK which must be defined in the VAdmTeamMembershipMeta class or an exception is generated.</param>
		/// <returns>Parent entity. NULL if the FK fields haven't been set or if the entity with the given key values doesn't exist.</returns>
		public override IEntity GetParent(DbRelation foreignKey)
		{
			throw new Exception("No foreign keys are defined in the VAdmTeamMembershipMeta class.");
		}

		/// <summary>
		/// Sets the given value into the member that represents the parent entity defined by the foreign key.
		/// </summary>
		/// <param name="foreignKey">FK which must be defined in the CFunctionsMeta class or an exception is generated.</param>
		/// <param name="entity">Parent entity. May be NULL. Must be an instance of the CFunctionsEntity or a derived class.</param>
		public override void SetParent(DbRelation foreignKey, IEntity entity)
		{
			throw new Exception("No foreign keys are defined in the VAdmTeamMembershipMeta class.");
		}

		#endregion

		/// <summary>
		/// Gets typed IDbTable object for the entity's table/view.
		/// </summary>
		public VAdmTeamMembershipMeta Table
		{
			get {return (VAdmTeamMembershipMeta) _Table;}
		}

		#region Public properties mapped to database columns.
		
		/// <summary>
		/// Gets or sets the value which is mapped to the non-nullable field 'OrganizationId'.
		/// If null-check is enabled a NoNullAllowedException is thrown if getter is used before the value has been set.
		/// </summary>
		public virtual int OrganizationId
		{
			get
			{
				if (_OrganizationId == null)
				{
					if (this.NullCheckEnabled)
						throw new NoNullAllowedException("VAdmTeamMembershipEntity.get_OrganizationId: OrganizationId is not set yet.");
					else
						return default(int);
				}
        
				return _OrganizationId.Value;
			}
			set
			{
				_OrganizationId = value;
			}
		}
		
		/// <summary>
		/// Gets or sets the value which is mapped to the non-nullable field 'UserId'.
		/// If null-check is enabled a NoNullAllowedException is thrown if getter is used before the value has been set.
		/// </summary>
		public virtual int UserId
		{
			get
			{
				if (_UserId == null)
				{
					if (this.NullCheckEnabled)
						throw new NoNullAllowedException("VAdmTeamMembershipEntity.get_UserId: UserId is not set yet.");
					else
						return default(int);
				}
        
				return _UserId.Value;
			}
			set
			{
				_UserId = value;
			}
		}
		
		/// <summary>
		/// Gets or sets the value which is mapped to the non-nullable field 'TeamId'.
		/// If null-check is enabled a NoNullAllowedException is thrown if getter is used before the value has been set.
		/// </summary>
		public virtual int TeamId
		{
			get
			{
				if (_TeamId == null)
				{
					if (this.NullCheckEnabled)
						throw new NoNullAllowedException("VAdmTeamMembershipEntity.get_TeamId: TeamId is not set yet.");
					else
						return default(int);
				}
        
				return _TeamId.Value;
			}
			set
			{
				_TeamId = value;
			}
		}
		
		/// <summary>
		/// Gets or sets the value which is mapped to the non-nullable field 'IsTeamAdministrator'.
		/// If null-check is enabled a NoNullAllowedException is thrown if getter is used before the value has been set.
		/// </summary>
		public virtual bool IsTeamAdministrator
		{
			get
			{
				if (_IsTeamAdministrator == null)
				{
					if (this.NullCheckEnabled)
						throw new NoNullAllowedException("VAdmTeamMembershipEntity.get_IsTeamAdministrator: IsTeamAdministrator is not set yet.");
					else
						return default(bool);
				}
        
				return _IsTeamAdministrator.Value;
			}
			set
			{
				_IsTeamAdministrator = value;
			}
		}
		
		/// <summary>
		/// Gets or sets the value which is mapped to the non-nullable field 'CanWrite'.
		/// If null-check is enabled a NoNullAllowedException is thrown if getter is used before the value has been set.
		/// </summary>
		public virtual bool CanWrite
		{
			get
			{
				if (_CanWrite == null)
				{
					if (this.NullCheckEnabled)
						throw new NoNullAllowedException("VAdmTeamMembershipEntity.get_CanWrite: CanWrite is not set yet.");
					else
						return default(bool);
				}
        
				return _CanWrite.Value;
			}
			set
			{
				_CanWrite = value;
			}
		}
		
		/// <summary>
		/// Gets or sets the value which is mapped to the non-nullable field 'CanDelete'.
		/// If null-check is enabled a NoNullAllowedException is thrown if getter is used before the value has been set.
		/// </summary>
		public virtual bool CanDelete
		{
			get
			{
				if (_CanDelete == null)
				{
					if (this.NullCheckEnabled)
						throw new NoNullAllowedException("VAdmTeamMembershipEntity.get_CanDelete: CanDelete is not set yet.");
					else
						return default(bool);
				}
        
				return _CanDelete.Value;
			}
			set
			{
				_CanDelete = value;
			}
		}
		
		#endregion
		
		#region NewEntity static methods suitable for usage in EntityBuilder<T>.

		/// <summary>Creates new entity and initializes all members of with the given values.</summary>
		/// <param name="table">Metadata for table/view to which the entity belongs to.</param>
		/// <param name="entityState">Indicates the state of entity with regard to data-source.</param>
		/// <param name="values">Array which contains values for all properties mapped to database columns in the following order: OrganizationId, UserId, TeamId, IsTeamAdministrator, CanWrite, CanDelete.</param>
		/// <remarks>This is the fastest method to initialize an entity as it directly initializes all members of base and derived class, 
		/// skips all validation checks and doesn't attempt to convert provided value data types. The method is typically used in combination 
		/// with IDataConverter objects which retrieve property values directly from IDataReader objects.</remarks>
		public static VAdmTeamMembershipEntity NewEntity(IDbTable table, EntityState entityState, object[] values)
		{
			return new VAdmTeamMembershipEntity(table, entityState, (int)values[0], (int)values[1], (int)values[2], (bool)values[3], (bool)values[4], (bool)values[5]);
		}

		/// <summary>Creates new entity and initializes members for which values are defined in the array.</summary>
		/// <param name="table">Metadata for table/view to which the entity belongs to.</param>
		/// <param name="entityState">Indicates the state of entity with regard to data-source.</param>
		/// <param name="values">Array which contains values or nulls for all properties mapped to database columns in the following order: OrganizationId, UserId, TeamId, IsTeamAdministrator, CanWrite, CanDelete.</param>
		/// <remarks>This is the fastest method to initialize an entity as it directly initializes all members of base and derived class, 
		/// skips all validation checks and doesn't attempt to convert provided value data types. The method is typically used in combination 
		/// with IObjectReader objects which retrieve property values directly from IDataReader objects.</remarks>
		public static VAdmTeamMembershipEntity NewPartialEntity(IDbTable table, EntityState entityState, object[] values)
		{
			return new VAdmTeamMembershipEntity(table, entityState, CastTo<int>(values[0]), CastTo<int>(values[1]), CastTo<int>(values[2]), CastTo<bool>(values[3]), CastTo<bool>(values[4]), CastTo<bool>(values[5]));
		}

		private static T? CastTo<T>(object val)
			where T : struct
		{
			if (IsNull(val))
				return null;
			else
				return (T)val;
		}

		private static bool IsNull(object val)
		{
			return (val == DBNull.Value || val == null);
		}
    
		private static object ReplaceDbNull(object dbValue)
		{
			return (dbValue != DBNull.Value) ? dbValue : null;
		}

		#endregion
	}

	/// <summary>
	/// Typed IDbTable class for the table/view 'VAdmTeamMembership'.
	/// </summary>
	[Serializable]
	public sealed class VAdmTeamMembershipMeta : SealedDbTable
	{
		static VAdmTeamMembershipMeta()
		{
			ReadSequenceOverrideFromConfig();
			ReadColumnNamesFromConfig();
			ImmutableColumnProperties = CreateImmutableColumnProperties();
			ImmutableTableProperties = CreateImmutableTableProperties();
		}
    
		#region Configuration.
		
		static readonly string[] SequenceNameOverrides = new string[6];
		static readonly bool?[] AutoIncrementOverrides = new bool?[6];
    
		private static void ReadSequenceOverrideFromConfig()
		{
			SequenceNameOverrides[0] = ConfigurationManager.AppSettings["BizElements.BusinessLayer.VAdmTeamMembership.OrganizationId.SequenceName"];
			AutoIncrementOverrides[0] = (SequenceNameOverrides[0] != null) ? (bool?)true : null;
			SequenceNameOverrides[1] = ConfigurationManager.AppSettings["BizElements.BusinessLayer.VAdmTeamMembership.UserId.SequenceName"];
			AutoIncrementOverrides[1] = (SequenceNameOverrides[1] != null) ? (bool?)true : null;
			SequenceNameOverrides[2] = ConfigurationManager.AppSettings["BizElements.BusinessLayer.VAdmTeamMembership.TeamId.SequenceName"];
			AutoIncrementOverrides[2] = (SequenceNameOverrides[2] != null) ? (bool?)true : null;
			SequenceNameOverrides[3] = ConfigurationManager.AppSettings["BizElements.BusinessLayer.VAdmTeamMembership.IsTeamAdministrator.SequenceName"];
			AutoIncrementOverrides[3] = (SequenceNameOverrides[3] != null) ? (bool?)true : null;
			SequenceNameOverrides[4] = ConfigurationManager.AppSettings["BizElements.BusinessLayer.VAdmTeamMembership.CanWrite.SequenceName"];
			AutoIncrementOverrides[4] = (SequenceNameOverrides[4] != null) ? (bool?)true : null;
			SequenceNameOverrides[5] = ConfigurationManager.AppSettings["BizElements.BusinessLayer.VAdmTeamMembership.CanDelete.SequenceName"];
			AutoIncrementOverrides[5] = (SequenceNameOverrides[5] != null) ? (bool?)true : null;
		}

		static readonly string[] ColumnNames = new string[6];

		private static void ReadColumnNamesFromConfig()
		{
			ColumnNames[0] = BizElements.BusinessLayer.Catalog.GetColumnNameOverride("VAdmTeamMembership", "OrganizationId") ?? "OrganizationId";
			ColumnNames[1] = BizElements.BusinessLayer.Catalog.GetColumnNameOverride("VAdmTeamMembership", "UserId") ?? "UserId";
			ColumnNames[2] = BizElements.BusinessLayer.Catalog.GetColumnNameOverride("VAdmTeamMembership", "TeamId") ?? "TeamId";
			ColumnNames[3] = BizElements.BusinessLayer.Catalog.GetColumnNameOverride("VAdmTeamMembership", "IsTeamAdministrator") ?? "IsTeamAdministrator";
			ColumnNames[4] = BizElements.BusinessLayer.Catalog.GetColumnNameOverride("VAdmTeamMembership", "CanWrite") ?? "CanWrite";
			ColumnNames[5] = BizElements.BusinessLayer.Catalog.GetColumnNameOverride("VAdmTeamMembership", "CanDelete") ?? "CanDelete";
		}

		#endregion
		
		#region Singleton/immutable configuration objects.

		static readonly DbColumnConfiguration[] ImmutableColumnProperties;
		static readonly DbTableConfiguration ImmutableTableProperties;

		private static DbColumnConfiguration[] CreateImmutableColumnProperties()
		{
			return new DbColumnConfiguration[]
			{
				new DbColumnConfiguration(ColumnNames[0], DbType.Int32, typeof(int), false, 0, AutoIncrementOverrides[0] ?? false, null, 0, false, false, false, "OrganizationId", int.MinValue, int.MaxValue, false, SequenceNameOverrides[0]),
				new DbColumnConfiguration(ColumnNames[1], DbType.Int32, typeof(int), false, 1, AutoIncrementOverrides[1] ?? false, null, 0, false, false, false, "UserId", int.MinValue, int.MaxValue, false, SequenceNameOverrides[1]),
				new DbColumnConfiguration(ColumnNames[2], DbType.Int32, typeof(int), false, 2, AutoIncrementOverrides[2] ?? false, null, 0, false, false, false, "TeamId", int.MinValue, int.MaxValue, false, SequenceNameOverrides[2]),
				new DbColumnConfiguration(ColumnNames[3], DbType.Boolean, typeof(bool), false, 3, AutoIncrementOverrides[3] ?? false, null, 0, false, false, false, "IsTeamAdministrator", null, null, false, SequenceNameOverrides[3]),
				new DbColumnConfiguration(ColumnNames[4], DbType.Boolean, typeof(bool), false, 4, AutoIncrementOverrides[4] ?? false, null, 0, false, false, false, "CanWrite", null, null, false, SequenceNameOverrides[4]),
				new DbColumnConfiguration(ColumnNames[5], DbType.Boolean, typeof(bool), false, 5, AutoIncrementOverrides[5] ?? false, null, 0, false, false, false, "CanDelete", null, null, false, SequenceNameOverrides[5]),
			};
		}

		private static DbTableConfiguration CreateImmutableTableProperties()
		{
			return new DbTableConfiguration
			(
				BizElements.BusinessLayer.Catalog.GetTableNameOverride("VAdmTeamMembership") ?? "VAdmTeamMembership",
				new BizElements.BusinessLayer.Catalog(),
				ImmutableColumnProperties,
				new int[] { },
				new string[] { },
                /*is view*/ true
			);
		}
		
		#endregion
		
		#region Constructors.

		/// <summary>
		/// Initializes a new instance of VAdmTeamMembershipMeta class.
		/// </summary>
		public VAdmTeamMembershipMeta()
			: base(ImmutableTableProperties, null, false)
		{
		}

		/// <summary>
		/// Initializes a new instance of VAdmTeamMembershipMeta class.
		/// </summary>
		/// <param name="alias">Object alias. If NULL then it will be equal to the table name.</param>
		public VAdmTeamMembershipMeta(string alias)
			: base(ImmutableTableProperties, alias, false)
		{
		}

		/// <summary>
		/// Initializes a new instance of VAdmTeamMembershipMeta class.
		/// </summary>
		/// <param name="setPrefixedColumnAliases">Whether to change aliases of all columns so that they start with prefix (usually table name).</param>
		public VAdmTeamMembershipMeta(bool setPrefixedColumnAliases)
			: base(ImmutableTableProperties, null, setPrefixedColumnAliases)
		{
		}

		/// <summary>
		/// Initializes a new instance of VAdmTeamMembershipMeta class.
		/// </summary>
		/// <param name="alias">Object alias. If NULL then it will be equal to the table name.</param>
		/// <param name="setPrefixedColumnAliases">Whether to change aliases of all columns so that they start with prefix (usually table name).</param>
		public VAdmTeamMembershipMeta(string alias, bool setPrefixedColumnAliases)
			: base(ImmutableTableProperties, alias, setPrefixedColumnAliases)
		{
		}

		#endregion

		#region CreateForeignKeys.

		/// <summary>
		/// Initializes an array of relations used by foreign keys.
		/// Only relations to other generated IDbTable classes are created.
		/// </summary>
		protected override DbRelation[] CreateForeignKeys()
		{
			DbRelation[] foreignKeys = new DbRelation[0];
      
			return foreignKeys;
		}

		#endregion

		#region New* methods.
    
		/// <summary>
		/// Creates a new VAdmTeamMembershipEntity object.
		/// </summary>
		/// <returns>New entity.</returns>
		public override IEntity NewEntity()
		{
			return new VAdmTeamMembershipEntity(this);
		}
    
		/// <summary>
		/// Creates a new EntityReader&lt;VAdmTeamMembershipEntity&gt; object.
		/// </summary>
		/// <returns>An instance of EntityReader&lt;VAdmTeamMembershipEntity&gt; class.</returns>
		public override IObjectReader NewEntityReader()
		{
			// Use default EntityReader<T>() constructor when targeting SQLite database or when column types are compatible/convertible, but do not exactly match, entity property types.
			return new EntityReader<VAdmTeamMembershipEntity>(VAdmTeamMembershipEntity.NewEntity);
		}

		#endregion

		#region Clone.

		/// <summary>
		/// Creates another IDbTable object for the same table/view.
		/// </summary>
		/// <param name="cloneAlias">Clone alias.</param>
		/// <returns>Clone.</returns>
		public override IDbTable Clone(string cloneAlias)
		{
			return new VAdmTeamMembershipMeta(cloneAlias);
		}

		/// <summary>
		/// Creates another IDbTable object for the same table/view.
		/// </summary>
		/// <param name="cloneAlias">Clone alias.</param>
		/// <param name="setPrefixedAliases">Specifies whether cloned columns will have prefixed aliases.</param>
		/// <returns>Clone.</returns>
		public override IDbTable Clone(string cloneAlias, bool setPrefixedAliases)
		{
			return new VAdmTeamMembershipMeta(cloneAlias, setPrefixedAliases);
		}

		#endregion

		#region Columns.
    
		/// <summary>
		/// Gets metadata for 'OrganizationId' column.
		/// </summary>
		public IDbColumn OrganizationId
		{
			get {return this.Columns[0];}
		}
			
		/// <summary>
		/// Gets metadata for 'UserId' column.
		/// </summary>
		public IDbColumn UserId
		{
			get {return this.Columns[1];}
		}
			
		/// <summary>
		/// Gets metadata for 'TeamId' column.
		/// </summary>
		public IDbColumn TeamId
		{
			get {return this.Columns[2];}
		}
			
		/// <summary>
		/// Gets metadata for 'IsTeamAdministrator' column.
		/// </summary>
		public IDbColumn IsTeamAdministrator
		{
			get {return this.Columns[3];}
		}
			
		/// <summary>
		/// Gets metadata for 'CanWrite' column.
		/// </summary>
		public IDbColumn CanWrite
		{
			get {return this.Columns[4];}
		}
			
		/// <summary>
		/// Gets metadata for 'CanDelete' column.
		/// </summary>
		public IDbColumn CanDelete
		{
			get {return this.Columns[5];}
		}
			
		#endregion
    
		#region Foreign keys.
		
		#endregion

		#region Parent entity property name getters.
		
		#endregion

		#region Children.
    
		/// <summary>
		/// Gets tables which reference the current table.
		/// </summary>
		/// <returns>Array of tables or empty array if the current table is not referenced by other objects.</returns>
		public override IDbTable[] GetChildTables()
		{
			return new IDbTable[]
			{
			};
		}

		/// <summary>
		/// Gets relations where current table acts as a parent.
		/// </summary>
		/// <returns>Array of relations or empty array if the current table is not referenced by other objects.</returns>
		public override DbRelation[] GetChildRelations()
		{
			return new DbRelation[]
			{
			};
		}

		#endregion
	}
}
